<!DOCTYPE html>
<html>
  <head>
  	<div th:include="base-libs :: base-libs" />
    <title>放号规则设置-新增/修改</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <style>
    	.hidden{
    		display:none;
    	}
    	.combo{
    		width:96% !important
    	}
    	.validatebox-text{
    		width:100% !important;
    	}
    </style>
    
    <script th:inline="javascript">
	    /**读取request中的初始化数据*/
	    var requestData = [[${requestData}]];
	</script>
	<script>
		var isExitFhgzTip = "";
		$(function(){
            $(this).registerManagerPage();
			initView();
			initData();
		})
		
		function initView(){
			//保存
			$("#btnBc").click(function(){
				if($(".form-control").QuickValidate()){
				    if(!StringUtils.isEmpty(isExitFhgzTip)){
						$.QuickAlert.alertFail({content: isExitFhgzTip});
					}else{
						$.QuickRemote.AjaxFiledFormSubmit("fhgzszForm", saveHandler, null);
					}
				}
			})
			
			//返回
			$("#btnFh").click(function(){
				$.QuickUrlUtils.redirectUrl("index.html");
			})
			
			//放号时间change
			$("#hours,#minutes").change(function(){
				var hours = $("#hours").val();
				var minutes=$("#minutes").val();
				$("#FHSJ").val(hours+":"+minutes);
			})
			
			//放号时间
			var $hours = $("#hours");
			for(var i=0;i<24;i++){
				if(i<10) i = '0' + i;
				var option = $("<option>").html(i).val(i);
				$hours.append(option);
			}
			var $minutes = $("#minutes");
			for(var i=0;i<60;i++){
				if(i<10) i = '0' + i;
				var option = $("<option>").html(i).val(i);
				$minutes.append(option);
			}
			
			//放号规则
			$("#GZFLDM").change(function(){
				var optionText = $(this).children(':selected').text();
				if(optionText=='请选择') optionText = '';
				$("#GZFLMC").val(optionText);
			})
			
			/** 医疗机构combogrid */
			var readonly = !requestData["isManager"];
			$("#combogridYljg").combogrid({
	            height: 30
	            ,width: 300
	            ,panelWidth: 700
	            ,singleSelect: true
	            ,pagination: true
	            ,idField: 'PTJGID'
	            ,textField: 'YLJGMC'
	            ,mode: "remote"
	            ,readonly: readonly
	            ,hasDownArrow: !readonly
	            ,url: "/console/yljgxx/queryPageSummary.service"
	            ,delay: 1000
	            ,reversed: false
	            ,fitColumns: true
	            ,columns:[[
	                {field:'YLJGMC',title:'机构名称',width:240},
	                {field:'XZQHMC',title:'行政区划',width:80},
	                {field:'WSJGLBMC',title:'机构类别',width:80},
	                {field:'YYDJMC',title:'机构等级',width:80}
	            ]]
	            ,onBeforeLoad: function(queryParams) {
	                var url = $(this).datagrid("options")["url"];
					/*URL不等空时再发送请求*/
	                if (!readonly) {
	                    queryParams["pageSize"] = queryParams["rows"];
	                    queryParams["pageNumber"] = queryParams["page"];
	                    queryParams["YLJGMC"] = queryParams["q"];
	                    var result = [];
	                    $("#YJKSDM").createOptions(result,{textField : "KSMC" , valueField : "KSDM"});
	                    return true;
	                }else{
	                    return false;
	                }
	            },
	            onClickRow : function(rowIndex, rowData){
	            	$("#YLJGDM").val(rowData.YLJGDM);
	    			$("#YLJGMC").val(rowData.YLJGMC);
	    			$("#PTJGID").val(rowData.PTJGID);
	    			$.QuickRemote.AjaxJson("/" + contextRoot + "fhgzsz/isExit", function(result){
						if(result.state==1){ //查询成功
							if(result.info){ //查询结果
                                $.QuickAlert.alertFail({content: result.info});
                                isExitFhgzTip = result.info;
							}
						}
					}, {PTJGID: rowData.PTJGID});
	            },
	            onLoadSuccess : function(data){

				}
	        });
			
			//点击input展开combogrid
			$(".validatebox-text").click(function(){
				$('.combo-arrow').trigger('click');
			})
		}
		
		function initData(){
			var fhgzszData = StoreCache.removeCache("fhgzszData");
			if(!$.isEmptyObject(fhgzszData)){
				$("#combogridYljg").combogrid("setValue", fhgzszData);
				$("#type").val('update');
				$(".form-control").each(function(){
					var name = $(this).attr('name');
					$(this).val(fhgzszData[name]);
				})
				//放号时间
				initFhsj(fhgzszData.FHSJ);
			}else if(!requestData["isManager"]){
                $("#combogridYljg").combogrid("setValue", parent.userInfo);
                $("#YLJGDM").val(parent.userInfo.YLJGDM);
                $("#YLJGMC").val(parent.userInfo.YLJGMC);
                $("#PTJGID").val(parent.userInfo.PTJGID);
			}
			$("#hours").trigger("change");
		}
		
		/** 保存回调 */
		function saveHandler(result){
			if(result.state){
				$.QuickAlert.alertNormal(result.info, {callback: function(){
					$("#btnFh").trigger("click");
				}});
			}else{
				$.QuickAlert.alertFail({content: result.info});
			}
		}
		
		/** 载入-放号时间 */
		function initFhsj(FHSJ){
			if(!StringUtils.isEmpty(FHSJ)){
				var fhsjArr = FHSJ.split(":");
				$("#hours").val(fhsjArr[0]);
				$("#minutes").val(fhsjArr[1]);
			}
		}
	</script>
  </head>
  
  <body class="easyui-layout">
    <div region="center">
    	<h4 class="h4-title" style="text-align:center;margin:0;padding:0;font-size: 18px;">
			添加放号规则
		</h4>
		<form action="save" id="fhgzszForm">
			<input id="type" name="type" value="add" class="hidden"/>
			<input name="GZBH" class="form-control hidden" />

			<div></div>
	    	<table class="form-table">
				<tr>
					<td class="td-text titleTd"><label>所属医院</label></td>
					<td class="td-content" colspan="3">
						<input id="combogridYljg" />
					
						<input id="YLJGMC" name="YLJGMC" class="form-control hidden" 
						quick-config="label:'所属医院', validateProxy:'notNull'"/>
						<input id="PTJGID" name="PTJGID" class="form-control hidden"/>
						<input id="YLJGDM" name="YLJGDM" class="form-control hidden"/>
					</td>
				</tr>
				<tr>
					<td class="td-text titleTd"><label>放号时间</label></td>
					<td class="td-content">
						<select id="hours" style="width:20%;margin-right:5px" ></select>时
						<select id="minutes" style="width:20%;margin-left:15px;margin-right:5px"></select>分
						
						<input id="FHSJ" name="FHSJ" class="form-control hidden" quick-config="label:'放号时间', validateProxy:'notNull'"/>
					</td>
					<td class="td-text titleTd"><label>放号区间</label></td>
					<td class="td-content">
						<input name="FHQJ" class="form-control" placeholder="单位：天"
						quick-config="label:'放号区间', validateProxy:'notNull length num', length: '3'"/>
						<span>天</span>
					</td>
				</tr>
				<!--<tr>-->
					<!--<td class="td-text titleTd"><label>规则分类</label></td>-->
					<!--<td class="td-content" colspan="3">-->
						<!--<select id="GZFLDM" name="GZFLDM" class="form-control condition" style="width:37%"-->
						<!--quick-config="label:'规则分类', validateProxy:'notNull'">-->
							<!--<option value="">请选择</option>-->
							<!--<option value="guaHao">挂号</option>-->
							<!--<option value="zhuanZen">转诊</option>-->
							<!--<option value="yiji">医技</option>-->
							<!--<option value="chuangWei">床位</option>-->
						<!--</select>-->
						<!--<input id="GZFLMC" name="GZFLMC" class="form-control hidden" />-->
					<!--</td>-->
				<!--</tr>-->
				<tr>
					<td class="td-text titleTd"><label>包含当天</label></td>
					<td class="td-content">
						<select name="SFBHDT" class="form-control" quick-config="label:'包含当天', validateProxy:'notNull'">
							<option value="1">是</option>
							<option value="0">否</option>
						</select>
					</td>
					<td class="td-text titleTd"><label>是否启用</label></td>
					<td class="td-content">
						<select name="ZT" class="form-control" style="width:90.4%" quick-config="label:'是否启用', validateProxy:'notNull'">
							<option value="1">是</option>
							<option value="2">否</option>
						</select>
					</td>
				</tr>
			</table>
		</form>
    </div>
    
    <div region="south" style="height:50px;line-height:50px;text-align:center;overflow:hidden;border:0;border-top:1px solid #ddd">
    	<button id="btnBc" class="btn btn-info" type="button">保存</button>
    	<button id="btnFh" class="btn btn-info" type="button">返回</button>
    </div>
  </body>
</html>
